{extend name="main" /}

{block name="body"}
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
        <a><cite>{$param.admin_id|get_username}</cite></a>
        <a><cite>网站</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class=" layui-card-header layuiadmin-card-header-auto">
            <form class="layui-form" method="get">
                <input type="hidden" name="bcid" value="{:input('bcid')}"><!--保留当前位置的bcid参数-->
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <a href="{:url('edit',['admin_id'=>$param.admin_id])}" class="layui-btn" title="添加">
                            分配
                        </a>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-card-body">
            <table class="layui-table">
                <tr>
                    <th><b>站点名称</b></th>
                    <th><b>URL</b></th>
                    <th><b>账号</b></th>
                </tr>

                <tbody>
                {foreach name="list" item="vo"}
                <tr>
                    <td>{$vo.title}</td>
                    <td>{$vo.url}</td>
                    <td>
                        {if is_site_username($vo.id,get_username($param.admin_id))}
                        <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-xs">
                            账号存在
                        </a>
                        {else}
                        <a href="javascript:;" class="layui-btn layui-btn-warm layui-btn-xs" data-webid="{$vo.id}" onclick="makeSiteUser(this)">
                            一键生成
                        </a>
                        {/if}
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    var username = "{$param.admin_id|get_username}";
    function makeSiteUser(obj){
        var webid = $(obj).attr('data-webid');
        $.get("{:url('admin/ajax/makeSiteUser')}",{webid:webid,username:username},function(res){
            if(res.status){
                $(obj).removeAttr('onclick');
                $(obj).removeClass('layui-btn-warm');
                $(obj).text('账号存在');
                $(obj).addClass('layui-btn-primary');
            }
            layer.msg(res.msg);
        });
    }
</script>
{/block}